import {SqlApi} from "./mysql/sqlApi";


let fn_add = async (ctx, next) => {
    await SqlApi.setTable('user').add({name:'xiaolu',sex:'nan',lv:'10'})
        .then(result=>{
            ctx.body = result;
            console.log(SqlApi)
        })
};
let fn_updata = async (ctx, next) => {
    await SqlApi.setTable('user').setWhere({id:2}).update({name:'xiaolu',sex:'nan',lv:'222'})
        .then(result=>{
            ctx.body = result;
            console.log(SqlApi)
        })
};

let fn_delete = async (ctx, next) => {
    await SqlApi.setTable('user').setWhere({id:4}).delete()
        .then(result=>{
            ctx.body = result;
            console.log(SqlApi)
        })
};
let fn_getAll = async (ctx, next) => {
    await SqlApi.setTable('user').getAll()
        .then(result=>{
            ctx.body = result;
            console.log(SqlApi)
        })
};

let fn_select= async (ctx, next) => {
    await SqlApi.setTable('user').setWhere('id in (1,2,3,4)').select()
        .then(result=>{
            ctx.body = result;
            console.log(SqlApi)
        })
};
let fn_sqlApi = async (ctx, next) => {
    console.log(SqlApi)
};


let fn_leftJion = async (ctx, next)=>{
    await SqlApi.setTable('user')
        .setFields('user.name')
        .setJoin('post on  user.id = post.uid')
        .setJoin('replay on  replay.postId = post.id')
        .select()
        .then(result=>{
            ctx.body = result;
            console.log(SqlApi)
        })
}
module.exports = {
    'GET /add': fn_add,
    'GET /updata': fn_updata,
    'GET /delete': fn_delete,
    'GET /getAll': fn_getAll,
    'GET /select': fn_select,
    'GET /leftJoin': fn_leftJion,
};